﻿
//实时统计文本框字数(检测控件，用于显示字数的控件)
function calculateLength(which, displaycontrol) {
    var text = Trim(which.value);
    var length = 0;
    for (var i = 0; i < text.length; i++) {
        if (text.charCodeAt(i) >= 10000) {
            length++;
        } else {
            length = length + 0.5;
        }
    }
    document.getElementById(displaycontrol).innerHTML = parseInt(length);
}
//实现trim()方法
function LTrim(str) {
    var i;
    for (i = 0; i < str.length; i++) {
        if (str.charAt(i) != " " && str.charAt(i) != " ")
            break;
    }
    str = str.substring(i, str.length);
    return str;
}
function RTrim(str) {
    var i;
    for (i = str.length - 1; i >= 0; i--) {
        if (str.charAt(i) != " " && str.charAt(i) != " ")
            break;
    }
    str = str.substring(0, i + 1);
    return str;
}
function Trim(str) {
    return str.replace(/\s/g, '');
}